<template>
    <div style="padding: 0 20px">
        <!--<el-row class="line-text-title" type="flex" justify="middle">-->
        <!--<span class="title-medium text-important">参与医生列表</span>-->
        <!--</el-row>-->
        <!--<el-row class="line-text">-->
        <!--<span class="content-text">{{ doctorListString }}</span>-->
        <!--</el-row>-->
        <el-row class="line-text-title" type="flex" justify="middle">
            <span class="title-medium text-important">讨论内容</span>
        </el-row>
        <div style="height: 580px; overflow-y: scroll">
            <el-row
                v-for="(msg, index) in messageList"
                :key="index"
                style="margin-top: 10px"
            >
                <div>
                    <span class="discussion-head" style="line-height: 24px">
                        {{ msg.createUserName }} ({{ msg.createTime }}):
                    </span>
                </div>
                <div>
                    <span style="line-height: 30px; font-size: 16px">
                        {{ msg.content }}
                    </span>
                </div>
            </el-row>
        </div>
        <el-row class="line-text">
            <span class="title-medium text-important">医生列表</span>
            <span
                class="content-text"
                style="margin-left: 10px"
                v-html="doctorListString"
            ></span>
        </el-row>
        <el-row style="margin-top: 10px">
            <el-col :span="16">
                <el-input
                    type="textarea"
                    :rows="3"
                    style="width: 100%"
                    placeholder="请输入内容"
                    v-model="content"
                >
                </el-input>
            </el-col>
            <el-col :span="4">
                <el-button
                    @click="contentSend"
                    type="primary"
                    size="mini"
                    style="margin: 0 10px"
                    >发送</el-button
                >
            </el-col>
        </el-row>
    </div>
</template>

<script>
import _ from 'lodash';
import diagnosisDefaultBase from '@templates/diagnosisDefault';
const diagnosisDefault = _.clone(diagnosisDefaultBase);

const userLevelBase = [
    {
        level: 2,
        label: '初诊',
    },
    {
        level: 3,
        label: '核发',
    },
    {
        level: 4,
        label: '审核',
    },
    {
        level: 5,
        label: '终审',
    },
];

export default {
    name: 'diagnosisMatchDetailDiscussion',
    props: {
        diagnosis: {
            type: Object,
            default: diagnosisDefault,
        },
        messageList: {
            type: Array,
            default: () => [],
        },
        isTheseDoctor: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            userLevelList: userLevelBase,
            content: '',
            doctorListString: '',
        };
    },
    mounted() {
        // let string = "";
        // this.doctorList.forEach((doctor) => {
        //     const level = this.userLevelList.find(
        //         (t) => t.level === doctor.level
        //     );
        //     string += `${_.get(level, "label", "")}医生：${_.get(
        //         doctor,
        //         "name",
        //         ""
        //     )}    `;
        // });
        // return string;
        console.log(this.diagnosis);
        let string = '';
        for (let i = 0; i < this.diagnosis.diagnosisDetailList.length; i++) {
            const t = this.diagnosis.diagnosisDetailList[i];
            const levelItem = this.userLevelList.find(
                (item) => item.level === t.currentLevel
            );
            if (t.diagnosisType == 1) {
                string += `邀请(${t.doctorName})&nbsp&nbsp&nbsp&nbsp`;
            } else {
                string += `${levelItem.label}(${t.doctorName})&nbsp&nbsp&nbsp&nbsp`;
            }
            levelItem.name = t.id;
        }
        this.doctorListString = string;
    },
    methods: {
        async contentSend() {
            const { state } = this.$store;
            const diagnosisId = state.diagnosis.id;
            await this.$axios({
                method: 'POST',
                url: `/PROXY-Remote/diagnosis/${diagnosisId}/message-board`,
                data: {
                    content: this.content,
                },
            })
                .then((res) => {
                    if (res.data.code === 200) {
                        this.messageList.push(res.data.data);
                        this.content = '';
                    } else {
                        this.$message.warning(res.data.message);
                    }
                })
                .catch(() => {
                    this.$message.warning(res.data.message);
                });
        },
    },
};
</script>

<style scoped>
.discussion-head {
    font-size: 18px;
    font-weight: 700;
}
</style>
